#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

// #include <clique.h>

bool k_clique(vector<vector<bool> > szomszedsagi, int k);

vector<vector<bool> > szomszedsagi;    // inciedence matrix      //
int meret;

void read_clq(string file_name)
{
    int i,j,n,e,x,y;
    string type,line;
    // file_name=file_name+".clq";
    //  ifstream fin("matrix-mon-5.txt");
    ifstream fin(file_name.c_str());
    //ifstream fin("matrix.txt");
    if(!fin.is_open()) {
        cout<<"ERROR opening file"<<endl;
        exit(1);
    }

    /*  fin>>type; //type of image/matrix (P1)*/

    //eliminate comment lines
    while(fin.peek()=='c') {
        getline(fin,line);
        //comment=comment+"#"+line+'\n';
    }


    fin>>type; // p
    fin>>type; // edge
    fin>>meret; // vertexes
    fin>>e; // edges
    //cout<<"n: "<<N<<"; m: "<<m<<endl;

    szomszedsagi.resize(meret);
    for(i=0; i<meret; ++i) {
        szomszedsagi[i].resize(meret);
    }


    for(i=0; i<e; i++) {
        fin>>type; // e
        if(type=="e") {
            fin>>x;
            fin>>y;
            //cout<<"x: "<<x<<"; y: "<<y<<endl;
            szomszedsagi[x-1][y-1]=1;
            szomszedsagi[y-1][x-1]=1;
        }
    }
    fin.close();
}
double diffclock( clock_t clock1, clock_t clock2 ) {

        double diffticks = clock1 - clock2;
        double diffms    = diffticks / CLOCKS_PER_SEC;

        return diffms;
    }
int main(int argc, char** argv)
{
    if(argv[1]==NULL) {
        cout<<"usage: "<<endl<<argv[0]<<" IN_FILE.clq"<<endl;
        return 1;
    }
    string file_name(argv[1]);

    read_clq(file_name);

    int k = atoi(argv[2]);
    ++k;
    bool found=false;
    clock_t start, end;
    for(k; !found && k>2; --k) {
        start = clock();
        found=k_clique(szomszedsagi, k);
        end = clock();
        cout<<"k: "<<k<<" file_name: "<<file_name<<" time: "<<diffclock(end, start)<<endl;
    }
}
